package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.RoomTypePrice;
import com.eling.elcms.travel.model.view.SumRoomPrice;
import com.eling.elcms.travel.service.IRoomTypePriceManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
public class RoomTypePriceController extends BaseFormController{

	@Autowired
	private IRoomTypePriceManager roomTypePriceManager;
	
	@RequestMapping("/api/roomtypeprice/save")
    @ResponseBody
	public RoomTypePrice save(@ModelAttribute@ModelFilling RoomTypePrice roomTypePrice){
		return roomTypePriceManager.save(roomTypePrice);
	}
	
	@RequestMapping("/api/roomtypeprice/deleteandsave")
    @ResponseBody
	public List<RoomTypePrice> deleteAndSave(@ModelAttribute@ModelFilling RoomTypePrice roomTypePrice,
			@RequestParam(value="startDate") Date startDate,
			@RequestParam(value="endDate") Date endDate,
			@RequestParam(value="week") String week){
		return roomTypePriceManager.deleteAndSave(roomTypePrice,startDate,endDate,week);
	}
	
	@RequestMapping("/api/roomtypeprice/{pkRoomTypePrice}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkRoomTypePrice){
		roomTypePriceManager.remove(pkRoomTypePrice);
		return new Msg("删除成功");
	}
	
	@RequestMapping("/api/roomtypeprice/query")
    @ResponseBody
	public List<RoomTypePrice> query(@ModelAttribute RoomTypePrice cond){
		return roomTypePriceManager.query(cond);
	}
	
	@RequestMapping("/api/roomtypeprice/querysumroomprice")
    @ResponseBody
	public SumRoomPrice querySumRoomPrice(@ModelAttribute RoomTypePrice cond){
		return roomTypePriceManager.querySumRoomPrice(cond);
	}
	
	@RequestMapping("/api/roomtypeprice/search*")
	@ResponseBody
	public List<RoomTypePrice> search(@ModelAttribute SearchCondition sc,@ModelAttribute RoomTypePrice cond){
		sc.setQueryCondition(cond);
		return roomTypePriceManager.search(sc);
	}
}
